<script>
	export default {
		async onLaunch() {
            // 应用信息
            console.log('app-->vuex_app_info[获取缓存应用信息]:', this.vuex_app_info);
            if (!this.vuex_app_info || !Object.keys(this.vuex_app_info).length) {
                console.log('app-->apiAppDetail[调用应用信息接口]:');
                let appDetail = await this.$u.api.appDetail();
                console.log('app-->apiAppDetail[应用信息接口结果]:', appDetail);
                if (!appDetail) {
                    // 初始化失败
                    return this.$appLaunchReject({ message: '应用初始化失败' });
                }
                // 设置到本地存储
                this.$u.vuex('vuex_app_info', appDetail);
            }
            if (this.vuex_app_info.hasOwnProperty('config')) {
                // 站点配置
                let appConfig = this.vuex_app_info.config;
                console.log('app-->appConfig[应用配置信息]:', appConfig);
                // region 访问控制 +++++
                if (appConfig.hasOwnProperty('common') && appConfig.common.hasOwnProperty('view_client') && appConfig.common.view_client.indexOf(this.clientType) == -1) {
                    // 禁止访问跳转到错误页
                    return this.$appLaunchReject({ message: appConfig.common.view_client_disable_help });
                }
                // endregion
            }
            // #ifdef H5
            if (this.clientType == 'wechat_mobile' || this.clientType == 'wechat_computer') {
                // 微信客户端
                // 验证登陆信息
                let loginInfo = this.$wx.loginCheckFunc(this.vuex_wx_id);
                // 更新全局信息
                if (loginInfo && (!this.vuex_wx_id || this.vuex_wx_id != loginInfo.id || !this.vuex_wx_token || this.vuex_wx_token != loginInfo.token)) {
                    this.$u.vuex('vuex_wx_id', loginInfo.id);
                    this.$u.vuex('vuex_wx_token', loginInfo.token);
                }
                console.log('app->vuex_wx_token[缓存微信TOKEN]:', this.vuex_wx_token);
                // region 微信SDK +++++
                let wxJsSdkConfig = await this.$u.api.wxJsSdkConfig({
                    wx_id: this.vuex_wx_id,
                    wx_sign_link: window.location.href
                });
                if (wxJsSdkConfig) {
                    console.log('app->wxShareConfig[微信jssdk配置]:', wxJsSdkConfig);
                    this.$wx.sdk.config(JSON.parse(wxJsSdkConfig));
                    this.$wx.sdk.ready(() => {
                        this.$wx.sdk.hideMenuItems({
                            menuList: ['menuItem:share:qq', 'menuItem:share:weiboApp', 'menuItem:favorite', 'menuItem:share:facebook', 'menuItem:share:QZone', 'menuItem:copyUrl', 'menuItem:openWithQQBrowser', 'menuItem:openWithSafari']
                        });
                        this.$wx.sdk.updateAppMessageShareData({
                            title: this.$config.wx_share_title,
                            desc: this.$config.wx_share_desc,
                            link: this.$config.wx_share_link,
                            imgUrl: this.$config.wx_share_image,
                            success: function() {
                                // 设置成功
                            }
                        });
                        this.$wx.sdk.updateTimelineShareData({
                            title: this.$config.wx_share_title,
                            link: this.$config.wx_share_link,
                            imgUrl: this.$config.wx_share_image,
                            success: function() {
                                // 设置成功
                            }
                        });
                        // 分享到朋友圈
                        this.$wx.sdk.onMenuShareTimeline({
                            title: this.$config.wx_share_title,
                            link: this.$config.wx_share_link,
                            imgUrl: this.$config.wx_share_image,
                            success: function() {
                                // 用户确认后执行的回调函数
                            },
                            cancel: function() {
                                // 用户取消后执行的回调函数
                            }
                        });
                        //分享给朋友
                        this.$wx.sdk.onMenuShareAppMessage({
                            title: this.$config.wx_share_title,
                            desc: this.$config.wx_share_desc,
                            link: this.$config.wx_share_link,
                            imgUrl: this.$config.wx_share_image,
                            type: 'link',
                            dataUrl: '',
                            success: function() {
                                // 用户确认后执行的回调函数
                            },
                            cancel: function() {
                                // 用户取消后执行的回调函数
                            }
                        });
                    });
                }
                // endregion
            }
            // #endif
            // 初始化完成
            this.$appLaunchResolve(true);
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	// 引入uview-ui样式
    @import 'uview-ui/index.scss';
    @import '@/style/common.scss';
    page {
        background-color: #0ba1e1;
    }
</style>
